package sixkey.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import sixkey.Enums.BusinessTypeEnum;
import sixkey.Exception.SystemException;
import sixkey.Exception.TestException;
import sixkey.annotation.Log;
import sixkey.annotation.PermissionAnnotation;
import sixkey.domain.entity.User;
import sixkey.service.IUserService;
import sixkey.utils.ResCodeEnum;
import sixkey.utils.ResResult;
import sixkey.utils.ResponseInfo;

/**
 * ClassName:TestController
 * Package:sixkey.controller
 * Description
 *
 * @Author:@wenxueshi
 * @Create:2023/7/12 - 14:25
 * @Version:v1.0
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class TestController {

    private final IUserService userService;

    @Log(title = "测试玩呢",businessType = BusinessTypeEnum.INSERT)
    @GetMapping("/test")
    public void test() throws SystemException {
        log.info("测试日志保存到数据库是否成功");

//        log.trace("我是trace");
//        log.debug("我是debug");
//        log.info("我是info");
//        log.warn("我是warn");
//        log.error("我是error");
//        int i = 1 / 1;
//        if(i == 1){
//            throw new TestException();
//        }
    }

    //根据id获取用户
    @ApiOperation(value = "根据id获取用户")
    @GetMapping("/getById/{id}")
    public ResponseInfo getById(@PathVariable("id") Long id){
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getId,id);
        User user = userService.getOne(wrapper);
        return ResponseInfo.success(user);
    }
}
